<html>
<head><title>CC Watchman OptionPage</title></head>
<script type="text/javascript">

function isDefined( variable){
	return (typeof(window[variable]) == "undefined")?  false: true;
}

// Saves options to localStorage.
function save_options() {
	var select = document.getElementById("rsslink").value;
	var refreshInterval = document.getElementById("refreshinterval").value;
	
	if(select.substring(0, 43) == 'http://www.conquerclub.com/rss.php?user_id=' && !isDefined(refreshInterval) && refreshInterval >= 10){
		localStorage["rsslink"] = select;
		localStorage["refresh"] = refreshInterval;

		// Update status to let user know options were saved.
		var error = document.getElementById("error");
		error.innerHTML = "";
		var status = document.getElementById("status");
		status.innerHTML = "Options Saved.";
		setTimeout(function() {
			status.innerHTML = "";
		}, 750);
	} else {
		var error = document.getElementById("error");
		
		if(select.substring(0, 43) != 'http://www.conquerclub.com/rss.php?user_id=')
			error.innerHTML = "Error: Illegal url. Must be in the following format: http://www.conquerclub.com/rss.php?user_id=xxxxxx (xxxxxx = your userid).<br />The link can be found on the <a href=\"http://www.conquerclub.com/player.php?mode=mygames\">My Games</a> page on conquerclub.com under the RSS fead link.";
		else 
			error.innerHTML = "The Conquer Club RSS feed which is used by this extension is only updated every 5 minutes. So a refresh interval of less then 10 seconds is not allowed. (Only Numbers 0-9 are allowed!)";
		setTimeout(function() {
			status.innerHTML = "";
		}, 2500);
	}
  
  
}

// Restores select box state to saved value from localStorage.
function restore_options() {
  var rsslink = localStorage["rsslink"];
  var refresh = localStorage["refresh"];
  
  if (rsslink) {
    document.getElementById("rsslink").value = rsslink;
  }
  
  if(refresh){
	document.getElementById("refreshinterval").value = refresh;
  }
  
  return;  
}

</script>

<body onload="restore_options()">

<div id="status"></div>
<div id="error" style="color:red;font-weight:bold;"></div>

Rss Link (Find it <a href="http://www.conquerclub.com/player.php?mode=mygames">here</a>!):
<input id="rsslink" type="text" id="rsslink" name="rsslink" />
<br />
Refresh Interval:
<input id="refreshinterval" type="text" id="refreshinterval" name="refreshinterval" /> Seconds

<br>
<button onclick="save_options()">Save</button>
</body>
</html>